*THIS DO-FILE REPRODUCES ALL ADMIN DATA RESULTS REPORTED IN CARLSSON & FINSERAAS (2025) "WORKPLACE PEER EFFECTS IN TURNOUT", JOP
*SEE README FILE FOR INFORMATION ON DATA ACCESS
*TO RUN THE DO FILE YOU NEED TO INSTALL THE PACKAGES reghdfe, ivreg2, coefplot, binscatter, binscatter2, gtools USING THE STATA COMMAND ssc install

********************************************************************
*** Program defining global macros and creating covariates *********
********************************************************************
capture program drop setup_macros_covariates
program setup_macros_covariates 

	*** Global macros for covariates ***
	global Other_X2 "IndexWorkerVoted2010 IndexWorkerVoted2010Miss  i.WP_HPG_type"
	global Other_X "Relative_Voted2010 IndexWorkerVoted2010 IndexWorkerVoted2010Miss  i.WP_HPG_type"

	* Relatives of workplace peers
	global WP_Relative_X "WP_Relative_Age2010 WP_Relative_Income WP_Relative_Married WP_Relative_NumberOfChildren WP_Relative_Employed"

	* Differece between relatives and index worker
	capture drop diffIndexRel_*
	gen diffIndexRel_Age2010 = Age2010 - WP_Relative_Age2010
	gen diffIndexRel_Income = Income - WP_Relative_Income
	gen diffIndexRel_Married = Married - WP_Relative_Married
	gen diffIndexRel_NumChild = NumberOfChildren - WP_Relative_NumberOfChildren
	global DiffIndexRel "diffIndexRel_Age2010 diffIndexRel_Income diffIndexRel_Married diffIndexRel_NumChild"

	* Interactions between WP_HPG_type and Relatives of workplace peers
	capture drop WP_HPG_type_*  WP_HPG_Edu_*
	tab WP_HPG_type, gen(WP_HPG_type_)
	forvalues var_num = 1(1)40  {
	 gen WP_HPG_Edu_`var_num'_2 = WP_HPG_type_`var_num' * WP_Relative_EduHighSchool
	 gen WP_HPG_Edu_`var_num'_3 = WP_HPG_type_`var_num' * WP_Relative_EduCollege
	 gen WP_HPG_Edu_`var_num'_4 = WP_HPG_type_`var_num' * WP_Relative_EduMiss
	}
	ds WP_HPG_Edu*
	global WP_HPG_type_Edu "WP_HPG_Edu_1_2 WP_HPG_Edu_1_4 WP_HPG_Edu_2_2 WP_HPG_Edu_2_4 WP_HPG_Edu_3_2 WP_HPG_Edu_3_4  WP_HPG_Edu_4_2 WP_HPG_Edu_4_4 WP_HPG_Edu_5_2   WP_HPG_Edu_5_4 WP_HPG_Edu_6_2 WP_HPG_Edu_6_4  WP_HPG_Edu_7_2 WP_HPG_Edu_7_4 WP_HPG_Edu_8_2  WP_HPG_Edu_8_4 WP_HPG_Edu_9_2 WP_HPG_Edu_9_4  WP_HPG_Edu_10_2 WP_HPG_Edu_10_4 WP_HPG_Edu_11_2  WP_HPG_Edu_11_4 WP_HPG_Edu_12_2 WP_HPG_Edu_12_4   WP_HPG_Edu_13_2 WP_HPG_Edu_13_4 WP_HPG_Edu_14_2  WP_HPG_Edu_14_4 WP_HPG_Edu_15_2 WP_HPG_Edu_15_4  WP_HPG_Edu_16_2 WP_HPG_Edu_16_4 WP_HPG_Edu_17_2   WP_HPG_Edu_17_4 WP_HPG_Edu_18_2 WP_HPG_Edu_18_4   WP_HPG_Edu_19_2 WP_HPG_Edu_19_4 WP_HPG_Edu_20_2 WP_HPG_Edu_20_4"  
                      


	* Region 
	global FE "elec_district2018" 

	* Firm and HWP level
	capture drop SSNI_Section*
	capture tab SNI_Section, gen(SSNI_Section)
	global FIRM_X "Org_* Ftg_*"
	global WP_X "WP_Age2010 WP_Income WP_NumberOfChildren WP_Married WP_NumWorkers"

	* Sample restriction
	global insample "if WP_NumWorkers <= 50"
	* IV main controls
	global main_controls $Other_X $WP_HPG_type_Edu $WP_Relative_X $DiffIndexRel Voted2018
	* OLS main controls
	global OLS_main_controls $Other_X2 $WP_HPG_type_Edu $WP_Relative_X $DiffIndexRel Voted2018
	
	capture gen Age2010_2 = Age2010 * Age2010

end

*************************************************************************
*** TABLE 1: Main analysis ***
*************************************************************************
use Data/data_main_analysis_coworker_peers_18_65_years, clear
setup_macros_covariates

* OLS
reghdfe Voted2022 WP_Voted2018 $OLS_main_controls $insample, cluster(WP_HPG_id) absorb($FE)
 
*first stage
reghdfe WP_Voted2018 WP_Relative_Voted2010 $main_controls $insample, cluster(WP_HPG_id) absorb($FE)
 
*reduced form
reghdfe Voted2022 WP_Relative_Voted2010 $main_controls $insample, cluster(WP_HPG_id) absorb($FE)
 
* 2SLS with individual IV
ivreghdfe Voted2022  $main_controls (WP_Voted2018 = WP_Relative_Voted2010) $insample, cluster(WP_HPG_id) absorb($FE) first



*************************************************************************
*** FIGURE 2 ****
*************************************************************************

quietly reghdfe WP_Relative_Voted2010 $main_controls $insample, cluster(WP_HPG_id) absorb($FE) res(instrument_res)
quietly reghdfe Voted2022 $main_controls $insample, cluster(WP_HPG_id) absorb($FE) res(turnout_res)
quietly reghdfe WP_Voted2018  $main_controls $insample, cluster(WP_HPG_id) absorb($FE) res(wp_turnout_res)
quietly reg  wp_turnout_res instrument_res $insample, cluster(WP_HPG_id) 
predict pr_wp_turnout $insample, xb

*fs
binscatter2 wp_turnout_res instrument_res, reportreg  
binscatterhist  wp_turnout_res instrument_res , hist( wp_turnout_res instrument_res) nquantiles(20) mc(black) title("First stage") xtitle("Instrument (residualized)") ytitle("WP Turnout (residualized)") ylabel(,nogrid) xlabel(,nogrid) savegraph("firststage") replace

*rf
binscatter2 turnout_res instrument_res, reportreg  
binscatterhist turnout_res instrument_res, hist( turnout_res instrument_res) nquantiles(20) mc(black) title("Reduced form") xtitle("Instrument (residualized)") ytitle("Voted (residualized)") ylabel(,nogrid) xlabel(,nogrid)  ym(-.004) savegraph("reducedform") replace


*ss
binscatter2 turnout_res pr_wp_turnout, reportreg  
binscatterhist turnout_res pr_wp_turnout, hist( turnout_res pr_wp_turnout) nquantiles(20) mc(black) title("Second stage") xtitle("Predicted WP Turnout") ytitle("Voted (residualized)") ylabel(,nogrid) xlabel(,nogrid) ym(-.004) savegraph("secondstage") replace

*combined
graph combine "firststage"  "reducedform" "secondstage", c(3)

*Anderson-Rubin confidence interval:   [ .048265, .112472] 
ivreg2 turnout_res (wp_turnout_res=instrument_res), cl(WP_HPG_id)
 weakiv

 *probit
reg  Voted2022 pr_wp_turnout, cl(WP_HPG_id)
probit  Voted2022 pr_wp_turnout, cl(WP_HPG_id)
mfx

 
*************************************************************************
*** TABLE 2: Heterogeneity ***
*************************************************************************

* Dummies around median for continuous variables we do heterogeneity on
keep  $insample

foreach het_var of varlist Age2010 Income {

 summarize `het_var', detail
 gen d`het_var' = (`het_var' > r(mean))
 gen Not_d`het_var' = !d`het_var'
}

* Create interaction variables for heterogeneity analysis

g  Voted2010 = IndexWorkerVoted2010
foreach het_var of varlist Married Voted2010 EduCollege Female ParentsVoted2010   {
 gen Not_`het_var' = !`het_var'
}


foreach het_var of varlist Married Voted2010 EduCollege Female ParentsVoted2010  dAge2010 dIncome  {

 di "`het_var'"
 gen WP_Vote18_`het_var' = `het_var' * WP_Voted2018
 gen WP_Vote18_Not_`het_var' = Not_`het_var' * WP_Voted2018
 gen WP_RVote10_`het_var' = `het_var' * WP_Relative_Voted2010
 gen WP_RVote10_Not_`het_var' = Not_`het_var' * WP_Relative_Voted2010

}


ivreghdfe Voted2022  $main_controls (WP_Vote18_Voted2010 WP_Vote18_Not_Voted2010 =WP_RVote10_Voted2010 WP_RVote10_Not_Voted2010) $insample, cluster(WP_HPG_id) absorb($FE) 

ivreghdfe Voted2022  $main_controls ParentsVoted2010 (WP_Vote18_ParentsVoted2010 WP_Vote18_Not_ParentsVoted2010 =WP_RVote10_ParentsVoted2010 WP_RVote10_Not_ParentsVoted2010) $insample, cluster(WP_HPG_id) absorb($FE) 

ivreghdfe Voted2022  $main_controls (WP_Vote18_Female WP_Vote18_Not_Female =WP_RVote10_Female WP_RVote10_Not_Female) $insample, cluster(WP_HPG_id) absorb($FE) 

ivreghdfe Voted2022  $main_controls (WP_Vote18_dAge2010 WP_Vote18_Not_dAge2010 =WP_RVote10_dAge2010 WP_RVote10_Not_dAge2010) $insample, cluster(WP_HPG_id) absorb($FE) 

ivreghdfe Voted2022  $main_controls (WP_Vote18_EduCollege WP_Vote18_Not_EduCollege =WP_RVote10_EduCollege WP_RVote10_Not_EduCollege) $insample, cluster(WP_HPG_id) absorb($FE) 

ivreghdfe Voted2022  $main_controls (WP_Vote18_Married WP_Vote18_Not_Married =WP_RVote10_Married WP_RVote10_Not_Married) $insample, cluster(WP_HPG_id) absorb($FE) 

ivreghdfe Voted2022  $main_controls (WP_Vote18_dIncome WP_Vote18_Not_dIncome =WP_RVote10_dIncome WP_RVote10_Not_dIncome) $insample, cluster(WP_HPG_id) absorb($FE) 




*************************************************************************
*** FIGURE 3 ****
*************************************************************************

*first stages
quietly reghdfe WP_Vote18_ParentsVoted2010  $main_controls ParentsVoted2010  WP_RVote10_ParentsVoted2010 WP_RVote10_Not_ParentsVoted2010  $insample, cluster(WP_HPG_id)  absorb($FE) res(wp_turnout_pv_res)
predict pr_wp_turnout_pv, xb
 
quietly reghdfe WP_Vote18_Not_ParentsVoted2010  $main_controls ParentsVoted2010  WP_RVote10_ParentsVoted2010 WP_RVote10_Not_ParentsVoted2010  $insample, cluster(WP_HPG_id)  absorb($FE) res(wp_turnout_pvn_res)
predict pr_wp_turnout_pvn, xb

 
*figure
quietly reghdfe Voted2022 $main_controls ParentsVoted2010   pr_wp_turnout_pv pr_wp_turnout_pvn $insample,  absorb($FE) cluster(WP_HPG_id)
eststo pv: margins, at(pr_wp_turnout_pv=(0(.1)1) ParentsVoted2010=1 pr_wp_turnout_pvn=0) post 
quietly reghdfe Voted2022  $main_controls ParentsVoted2010 pr_wp_turnout_pv pr_wp_turnout_pvn $insample,  absorb($FE) cluster(WP_HPG_id)
eststo pvn: margins, at(pr_wp_turnout_pvn=(0(.1)1) ParentsVoted2010=0 pr_wp_turnout_pv=0) post

coefplot (pv, label(Parents voted in 2010) color(black) ciopts(lcolor(black) lp(dot))) (pvn, label(Parents did not vote in 2010) color(gs8) ciopts(lcolor(gs8) lp(dot))), at xtitle("Workplace turnout") ytitle("Turnout") ylabel(,nogrid) xlabel(,nogrid) legend(position(0) bplacement(seast))



******************************************************************
*********** TABLE 3 Placebo tests ***********
******************************************************************

* Placebo A - ranomly select any HPG which is the same type
use  Data/data_placebo_A_analysis_coworker_peers, replace
setup_macros_covariates

ivreghdfe Voted2022  $main_controls (WP_Voted2018 = WP_Relative_Voted2010) $insample, cluster(WP_HPG_id) absorb($FE) 


* Placebo B ranomly select a HPG of the same type in the same munic
use  Data/data_placebo_B_analysis_coworker_peers, replace
setup_macros_covariates

ivreghdfe Voted2022  $main_controls (WP_Voted2018 = WP_Relative_Voted2010) $insample, cluster(WP_HPG_id) absorb($FE) 


* Placebo C ranomly select a HPG of the same type in the same munic of the same size
use  Data/data_placebo_C_updated_analysis_coworker_peers, replace
setup_macros_covariates

ivreghdfe Voted2022  $main_controls (WP_Voted2018 = WP_Relative_Voted2010) $insample, cluster(WP_HPG_id) absorb($FE) 


*** Placebo test using voting in 2009 ***
use Data/data_main_analysis_coworker_peers_18_65_years, clear
setup_macros_covariates

rename WorkplaceId WorkplaceId_2018
rename P0846_lopnr_PeOrgNr lopenr_PeOrgNr_2018
merge 1:1 PersonId using Data/data_ind_X_2009,keepusing(WorkplaceId P0846_lopnr_PeOrgN)
drop if _merge==2
drop _merge
rename WorkplaceId WorkplaceId_2010
rename P0846_lopnr_PeOrgNr lopenr_PeOrgNr_2010

g Same_WP = WorkplaceId_2010 == WorkplaceId_2018
g Same_Firm = lopenr_PeOrgNr_2010==lopenr_PeOrgNr_2018

ivreghdfe voted2009  $main_controls   (WP_Voted2018 = WP_Relative_Voted2010) $insample & Same_Firm==1, cluster(WP_HPG_id) absorb($FE) 


*Plausibly exogenous 
quietly reghdfe WP_Relative_Voted2010 $main_controls $insample, cluster(WP_HPG_id) absorb($FE) res(instrument_res)
quietly reghdfe Voted2022 $main_controls $insample, cluster(WP_HPG_id) absorb($FE) res(turnout_res)
quietly reghdfe WP_Voted2018  $main_controls $insample, cluster(WP_HPG_id) absorb($FE) res(wp_turnout_res)
quietly reg  wp_turnout_res instrument_res $insample, cluster(WP_HPG_id) 
predict pr_wp_turnout $insample, xb

plausexog uci turnout_res (wp_turnout_res = instrument_res), vce(cluster WP_HPG_id) gmin(0) gmax(.009) grid(3)

*LB: .030 UP: .048

*****************************************************************
*********** TABLE 4  Heterogeneity by O*Net  ***********
***************************************************************

use Data/data_main_analysis_coworker_peers_18_65_years, clear
setup_macros_covariates

rename Ssyk4_2012_J16 ssyk2012
* Data from O*NET at the occupational level
merge m:1 ssyk2012 using Data/data_ONET_WorkWithOthers
drop if _merge == 2
drop _merge

capture drop ssyk3-WP_RelV2010_WorkOthersMiss

* Impute at the three digit level if missing at the four digit level
gen ssyk3 = floor(ssyk2012/10)
egen WorkWithOthers_3 = mean(WorkWithOthers), by(ssyk3)
replace WorkWithOthers = WorkWithOthers_3 if WorkWithOthers == .
gen ssyk2 = floor(ssyk2012/100)
tab ssyk2, miss

egen WorkWithOthers_2 = mean(WorkWithOthers), by(ssyk2)
replace WorkWithOthers = WorkWithOthers_2 if WorkWithOthers == .

gen ssyk1 = floor(ssyk2012/1000)
tab ssyk1, miss

egen WorkWithOthers_1 = mean(WorkWithOthers), by(ssyk1)
replace WorkWithOthers = WorkWithOthers_1 if WorkWithOthers == .

drop if WorkWithOthers == .

* Split the group where social interaction is very important or extremely important in two groups of approx. equal size.  
gen L_WorkOthers = WorkWithOthers <= 75
gen H_WorkOthers = WorkWithOthers >75

gen WP_Voted2018_L_WorkOthers = WP_Voted2018 * L_WorkOthers
gen WP_Voted2018_H_WorkOthers = WP_Voted2018 * H_WorkOthers

gen WP_RelV2010_L_WorkOthers = WP_Relative_Voted2010 * L_WorkOthers
gen WP_RelV2010_H_WorkOthers = WP_Relative_Voted2010 * H_WorkOthers

gen WP_Voted2018_WorkOthers = WP_Voted2018 * WorkWithOthers
gen WP_Relative_Voted2010_WorkOthers = WP_Relative_Voted2010 * WorkWithOthers

* Interaction with mean centered WorkWithOthers
summarize WorkWithOthers $insample, meanonly
gen WorkWithOthers_c = WorkWithOthers - r(mean)

gen WP_Voted2018_WorkOthers_c = WP_Voted2018 * WorkWithOthers_c
gen WP_Rel_Voted2010_WorkOthers_c = WP_Relative_Voted2010 * WorkWithOthers_c


* Sample split  
ivreghdfe Voted2022  $main_controls  L_WorkOther ///
(WP_Voted2018_L_WorkOthers  WP_Voted2018_H_WorkOthers   = WP_RelV2010_L_WorkOthers WP_RelV2010_H_WorkOthers ) /// 
$insample, cluster(WP_HPG_id) absorb($FE) 


* Continuous variable
ivreghdfe Voted2022 $main_controls WorkWithOthers_c ///
(WP_Voted2018 WP_Voted2018_WorkOthers_c = WP_Relative_Voted2010 WP_Rel_Voted2010_WorkOthers_c) ///
 $insample, cluster(WP_HPG_id) absorb($FE)
 

*****************************************************************
***********APPENDIX  ***********
***************************************************************


*****************************************************************
*********** TABLE A1 Descriptives *********
*****************************************************************
use Data/data_main_analysis_coworker_peers_18_65_years, clear
setup_macros_covariates

su Voted2022 WP_Voted2018 Relative_Voted2010 IndexWorkerVoted2010 IndexWorkerVoted2010Miss  $WP_Relative_X $DiffIndexRel  Female EduCollege Age2010 Income Married NumberOfChildren ParentsVoted2010 $insample 


*****************************************************************
*********** TABLE A2 Descriptives firms  *********
*****************************************************************


* 1. Save identifiers for sample of firms
use Data/data_main_analysis_coworker_peers_18_65_years, clear

setup_macros_covariates 
keep $insample
keep P0846_lopnr_PeOrgNr
duplicates drop
gen firm_in_sample = 1
save Data/tmp_firms_in_sample, replace

* 2. Save identifiers for population of firms
use Data/data_firm_X_2017, clear

* Detect inactive firms and outliers
drop if Ftg_Antal_anstallda < 2
drop if Ftg_Antal_anstallda == .
drop if Ftg_Nettoomsattning_miss == 1
drop if Ftg_Nettoomsattning <= 0 
drop if Org_Sni2007 == 0
drop if Org_LoneSum <= 0

gen double wage_per_employee = Org_LoneSum/Ftg_Antal_anstallda
drop if wage_per_employee < 0
sum wage_per_employee, det
* Drop below and above the 5th and 95th percentile
drop if wage_per_employee > 589 | wage_per_employee < 135

keep P0846_lopnr_PeOrgNr
duplicates drop 

save Data/tmp_firms_in_population, replace

* 3. Construct firm variables based on firm register and individual
* register on individuals working at the firms.

* First save SNI section
use Data/data_ind_X_2017, clear
keep if WP_P0846_lopnr_PeOrgNr != .
keep WP_P0846_lopnr_PeOrgNr WP_SNI_Section
rename WP_P0846_lopnr_PeOrgNr P0846_lopnr_PeOrgNr
rename WP_SNI_Section SNI_Section
duplicates drop
save Data/tmp_SNI_section, replace

* Then count number of workplaces
use Data/data_ind_X_2017, clear
keep if WP_P0846_lopnr_PeOrgNr != .
keep WP_P0846_lopnr_PeOrgNr WorkplaceId
rename WP_P0846_lopnr_PeOrgNr P0846_lopnr_PeOrgNr
duplicates drop
sort P0846_lopnr_PeOrgNr WorkplaceId
drop if WorkplaceId == .
collapse (count)NumWorkplaces = WorkplaceId, by(P0846_lopnr_PeOrgNr)
tab NumWorkplaces, miss
save Data/tmp_NumWorkplaces, replace

* Then save other variables
use Data/data_ind_X_2017, clear
keep if WP_P0846_lopnr_PeOrgNr != .
merge 1:1 PersonId using Data/data_voting_2018
drop if _merge == 2
drop _merge
rename WP_P0846_lopnr_PeOrgNr P0846_lopnr_PeOrgNr
keep P0846_lopnr_PeOrgNr Income Female Age2017 NumberOfChildren EduCollege Married Age2018 Voted2018 Ftg_Antal_anstallda Ftg_Nettoomsattning WorkplaceId
collapse (mean)Income (mean)Female (mean)NumberOfChildren (mean)EduCollege (mean)Married (mean)Age2018 (mean)Voted2018 (mean)Ftg_Antal_anstallda (mean)Ftg_Nettoomsattning (count)NumberEmployed = Female, by(P0846_lopnr_PeOrgNr)

save Data/tmp_firm_variables_population, replace

* 4. Merge 1 and 2, add variables from 3 and present firm descriptives

* Note: those in sample are also included in the populations, so 
* are dubplicates in the merged data
use Data/tmp_firms_in_sample, clear
append using Data/tmp_firms_in_population
replace firm_in_sample = 0 if firm_in_sample == .
 

* Add firm characteristics 
merge m:1 P0846_lopnr_PeOrgNr using Data/tmp_firm_variables_population
keep if _merge == 3
drop _merge
 
merge m:1 P0846_lopnr_PeOrgNr using Data/tmp_SNI_section
keep if _merge == 3
drop _merge
merge m:1 P0846_lopnr_PeOrgNr using Data/tmp_NumWorkplaces
keep if _merge == 3
drop _merge

foreach firm_X in Income Female NumberOfChildren EduCollege Married Age2018 Voted2018 Ftg_Antal_anstallda Ftg_Nettoomsattning  NumberEmployed  NumWorkplaces {
	bys firm_in_sample: sum `firm_X', det
}

bys firm_in_sample: tab SNI_Section



*****************************************************************
*********** TABLE A3 Worker characteristics and turnout *********
*****************************************************************
use Data/data_main_analysis_coworker_peers_18_65_years, clear
setup_macros_covariates

g  Voted2010 = IndexWorkerVoted2010

foreach het_var of varlist Age2010 Income {

 summarize `het_var', detail
 gen d`het_var' = (`het_var' > r(mean))
 gen Not_d`het_var' = !d`het_var'
}


reg Voted2022 Voted2010  IndexWorkerVoted2010Miss ParentsVoted2010 Female EduCollege dAge2010 dIncome Married $insample, vce(hc3) 


*****************************************************************
*********** TABLE A4 First stage by subgroups *********
*****************************************************************

use Data/data_main_analysis_coworker_peers_18_65_years, clear
setup_macros_covariates

reghdfe WP_Voted2018   WP_Relative_Voted2010  $main_controls $insample & Female==0, cluster(WP_HPG_id) absorb($FE)
 
reghdfe WP_Voted2018   WP_Relative_Voted2010  $main_controls $insample & Female==1, cluster(WP_HPG_id) absorb($FE)
 
reghdfe WP_Voted2018   WP_Relative_Voted2010 $main_controls $insample & EduCollege==0, cluster(WP_HPG_id) absorb($FE)
  
reghdfe WP_Voted2018   WP_Relative_Voted2010 $main_controls $insample & EduCollege==1, cluster(WP_HPG_id) absorb($FE)
 

*****************************************************************
*********** TABLE A5 Compliers  *********
*****************************************************************

use Data/data_main_analysis_coworker_peers_18_65_years, clear
setup_macros_covariates

*Binary treatment and instrument 
g WP_Voted2018_b = .
g WP_Relative_Voted2010_b=.
replace WP_Voted2018_b = 1 if WP_Voted2018==1
replace WP_Voted2018_b = 0 if WP_Voted2018<1

quietly reghdfe  WP_Relative_Voted2010  $main_controls $insample, cluster(WP_HPG_id) absorb($FE) res(WP_Relative_Voted2010_res)
xtile  WP_Relative_Voted2010_br =  WP_Relative_Voted2010_res $insample, n(2)
replace WP_Relative_Voted2010_br = WP_Relative_Voted2010_br -1 

ivdesc IndexWorkerVoted2010 WP_Voted2018_b  WP_Relative_Voted2010_br $insample, reps(2)
ivdesc Voted2018 WP_Voted2018_b  WP_Relative_Voted2010_br $insample, reps(2)
ivdesc ParentsVoted2010 WP_Voted2018_b  WP_Relative_Voted2010_br $insample, reps(2)
ivdesc Age2022 WP_Voted2018_b  WP_Relative_Voted2010_br $insample, reps(2)
ivdesc EduCollege WP_Voted2018_b  WP_Relative_Voted2010_br $insample, reps(2)
ivdesc Married WP_Voted2018_b  WP_Relative_Voted2010_br $insample, reps(2)
ivdesc Income WP_Voted2018_b  WP_Relative_Voted2010_br $insample, reps(2)
ivdesc Female WP_Voted2018_b  WP_Relative_Voted2010_br $insample, reps(2)


*****************************************************************
*********** TABLE A6 Exc. ineligible to vote in 2010 *********
*****************************************************************


* OLS
reghdfe Voted2022 WP_Voted2018 $main_controls  $insample &  Age2017>25, cluster(WP_HPG_id) absorb($FE)
 

* first stage
reghdfe WP_Voted2018  WP_Relative_Voted2010 $main_controls  $insample &  Age2017>25, cluster(WP_HPG_id) absorb($FE)
 

*reduced form
reghdfe Voted2022 WP_Relative_Voted2010 $main_controls  $insample &  Age2017>25, cluster(WP_HPG_id) absorb($FE)
 

* IV
ivreghdfe Voted2022 $main_controls (WP_Voted2018 = WP_Relative_Voted2010)  $insample &  Age2017>25, cluster(WP_HPG_id) absorb($FE) 
 
 


*****************************************************************
*********** TABLE A7 Binary instrument  *********
*****************************************************************

use Data/data_main_analysis_coworker_peers_18_65_years, clear
setup_macros_covariates


*Binary treatment and instrument 
g WP_Voted2018_b = .
g WP_Relative_Voted2010_b=.
replace WP_Voted2018_b = 1 if WP_Voted2018==1
replace WP_Voted2018_b = 0 if WP_Voted2018<1

quietly reghdfe  WP_Relative_Voted2010  $main_controls $insample, cluster(WP_HPG_id) absorb($FE) res(WP_Relative_Voted2010_res)
xtile  WP_Relative_Voted2010_br =  WP_Relative_Voted2010_res $insample, n(2)
replace WP_Relative_Voted2010_br = WP_Relative_Voted2010_br -1 

*   OLS
reghdfe Voted2022 WP_Voted2018_b $OLS_main_controls $insample, cluster(WP_HPG_id) absorb($FE)
 
* first stage
reghdfe WP_Voted2018  WP_Relative_Voted2010_br  $main_controls $insample, cluster(WP_HPG_id) absorb($FE)
 
*reduced form
reghdfe Voted2022 WP_Relative_Voted2010_br $main_controls $insample, cluster(WP_HPG_id) absorb($FE)
 
* IV
ivreghdfe Voted2022  $main_controls  (WP_Voted2018_b = WP_Relative_Voted2010_br) $insample, cluster(WP_HPG_id) absorb($FE) first
 
 
*****************************************************************
*********** TABLE A8 Alternative instrument  *********
*****************************************************************

 
use Data/data_main_analysis_coworker_peers_18_65_years_alt_instrument, clear
setup_macros_covariates


* OLS
reghdfe Voted2022 WP_Voted2018 $OLS_main_controls $insample, cluster(WP_HPG_id) absorb($FE)

*first stage
reghdfe WP_Voted2018 WP_Relative_Voted2010 $main_controls $insample, cluster(WP_HPG_id) absorb($FE)

*reduced form
reghdfe Voted2022 WP_Relative_Voted2010 $main_controls $insample, cluster(WP_HPG_id) absorb($FE)

* 2SLS with individual IV
ivreghdfe Voted2022  $main_controls (WP_Voted2018 = WP_Relative_Voted2010) $insample, cluster(WP_HPG_id) absorb($FE) first


*****************************************************************
*********** TABLE A9 Additional controls  ***********
***************************************************************
use Data/data_main_analysis_coworker_peers_18_65_years, clear
setup_macros_covariates


 global FIRM_X "Org_* Ftg_*"
	global WP_X "WP_Age2010 WP_Income WP_NumberOfChildren WP_Married WP_NumWorkers"
	
ds Org_*
foreach var of varlist `r(varlist)' {
	count if missing(`var')
	di  "`var': " r(N) " missing"
}

foreach var in WP_Age2010 WP_Income WP_NumberOfChildren WP_Married WP_NumWorkers {
	count if missing(`var')
	di  "`var': " r(N) " missing"
}


* i) Repeating main 
ivreghdfe Voted2022  $main_controls (WP_Voted2018 = WP_Relative_Voted2010) $insample, cluster(WP_HPG_id) absorb($FE) 


* ii) Adding workplace characteristics
ivreghdfe Voted2022  $main_controls  $WP_X   (WP_Voted2018 = WP_Relative_Voted2010) $insample, cluster(WP_HPG_id) absorb($FE) 

* iii) Adding firm characteristics
ivreghdfe Voted2022  $main_controls  $FIRM_X  (WP_Voted2018 = WP_Relative_Voted2010) $insample, cluster(WP_HPG_id) absorb($FE) 

* iv) Adding both  workplace and firm characteristics
ivreghdfe Voted2022  $main_controls $WP_X $FIRM_X (WP_Voted2018 = WP_Relative_Voted2010) $insample , cluster(WP_HPG_id) absorb($FE) 


*****************************************************************
*********** FIGURE A1: MTE  ***********
***************************************************************
use Data/data_main_analysis_coworker_peers_18_65_years, clear
setup_macros_covariates


*Binary treatment and instrument 
g WP_Voted2018_b = .
g WP_Relative_Voted2010_b=.
replace WP_Voted2018_b = 1 if WP_Voted2018==1
replace WP_Voted2018_b = 0 if WP_Voted2018<1

quietly reghdfe  WP_Relative_Voted2010  $main_controls $insample, cluster(WP_HPG_id) absorb($FE) res(WP_Relative_Voted2010_res)
xtile  WP_Relative_Voted2010_br =  WP_Relative_Voted2010_res $insample, n(2)
replace WP_Relative_Voted2010_br = WP_Relative_Voted2010_br -1 

foreach x in Voted2022 Voted2018 Relative_Voted2010 IndexWorkerVoted2010 IndexWorkerVoted2010Miss WP_Relative_Age2010 WP_Relative_Income WP_Relative_Married WP_Relative_NumberOfChildren WP_Relative_Employed diffIndexRel_Age2010 diffIndexRel_Income diffIndexRel_Married diffIndexRel_NumChild{
	quietly reghdfe `x' $WP_HPG_type_Edu, absorb($FE WP_HPG_type) res(`x'_res)
}
rename WP_Relative_NumberOfChildren_res WP_Relative_NChildren_res
rename IndexWorkerVoted2010Miss_res IndexWV2010Miss_res

global x_res "Voted2018_res Relative_Voted2010_res IndexWorkerVoted2010_res IndexWV2010Miss_res WP_Relative_Age2010_res WP_Relative_Income_res WP_Relative_Married_res WP_Relative_NChildren_res WP_Relative_Employed_res diffIndexRel_Age2010_res diffIndexRel_Income_res diffIndexRel_Married_res diffIndexRel_NumChild_res"

ivreghdfe Voted2022_res  $x_res (WP_Voted2018_b = WP_Relative_Voted2010_res) $insample, cluster(WP_HPG_id) nabsorb


mtefe Voted2022_res $x_res (WP_Voted2018_b = WP_Relative_Voted2010_res), vce(cluster WP_HPG_id) poly(2) trim(.02) 
est store normal


*****************************************************************
*********** TABLE A10: Attentuation bias  ***********
***************************************************************


use Data/data_main_analysis_coworker_peers_18_65_years, clear
setup_macros_covariates

tab WP_NumWorkers $insample, miss
gen LargeWP =  WP_NumWorkers > 7
gen SmallWP = WP_NumWorkers <= 7
gen WP_Voted2018_LargeWP = WP_Voted2018 * LargeWP
gen WP_Voted2018_SmallWP = WP_Voted2018 * SmallWP
gen WP_Relative_Voted2010_LargeWP = WP_Relative_Voted2010 * LargeWP
gen WP_Relative_Voted2010_SmallWP = WP_Relative_Voted2010 * SmallWP

***  ***

* OLS
reghdfe Voted2022 WP_Voted2018_LargeWP WP_Voted2018_SmallWP LargeWP $OLS_main_controls $insample, cluster(WP_HPG_id) absorb($FE)

* 2SLS with individual IV
ivreghdfe Voted2022  $main_controls  LargeWP  (WP_Voted2018_LargeWP WP_Voted2018_SmallWP = WP_Relative_Voted2010_SmallWP WP_Relative_Voted2010_LargeWP) $insample, cluster(WP_HPG_id) absorb($FE) 

test WP_Voted2018_LargeWP == WP_Voted2018_SmallWP

*****************************************************************
*********** FIGURE A2: Attentuation bias  ***********
***************************************************************

gen WP_Voted2018_One = WP_Voted2018 == 1
gen WP_Relative_Voted2010_One = WP_Relative_Voted2010 == 1

keep $insample

* Treatment
hist WP_Voted2018 if WP_Voted2018 < 1, title("A)", pos(11)) ytitle("Number of obs") freq width (.03) fcolor(white) lcolor(black) xtitle("") ylabel(, angle(60) format(%2.0f))
graph save "Stata output/treat_distr", replace

* Instrument
hist WP_Relative_Voted2010 if WP_Relative_Voted2010 < 1, title("B)", pos(11)) ytitle("Number of obs") freq width(.03) fcolor(white) lcolor(black) xtitle("") ylabel(, angle(60) format(%2.0f))
graph save "Stata output/IV_distr", replace

graph combine "Stata output/treat_distr" "Stata output/IV_distr", ycommon
 
*** Numbers mentioned in the text in Appendix Section K ***

* How many coworkers and relatives at the workplace 
* and the number of own relatives
use Data/data_main_analysis_coworker_peers_18_65_years, clear
keep $insample
gen NumRelativesOfOtherCoworkers =  WP_NumRelatives - NumberOfRelatives

sum WP_NumWorkers, det /* and subtract yourself */
sum NumberOfRelatives, det
sum WP_NumRelatives, det
sum NumRelativesOfOtherCoworkers, det

